unit LancamentosFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ComCtrls, ExtCtrls, DbCtrls, StdCtrls, EditBtn, DBGrids, Buttons,
  GerencialMainFr;

type

  { TLancamentosFrame }

  TLancamentosFrame = class(TGerencialMainFrame)
    dataInicial: TDateEdit;
    dataFinal: TDateEdit;
    DBGrid1: TDBGrid;
    DBLookupListBox1: TDBLookupListBox;
    DBText1: TDBText;
    DBText2: TDBText;
    SaldoAtualEdit: TDBText;
    TotalEdit: TDBText;
    DBText5: TDBText;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Panel1: TPanel;
    Panel10: TPanel;
    Panel11: TPanel;
    Panel12: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    Panel8: TPanel;
    Panel9: TPanel;
    SpeedButton1: TSpeedButton;
    procedure DBLookupListBox1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

implementation

uses
  GerencialDM, ContaDM;

{ TLancamentosFrame }

procedure TLancamentosFrame.DBLookupListBox1Click(Sender: TObject);
var
  I:integer;
  Soma:real;
begin
   with ContaData.ContaZQuery do begin
     Soma:=0;
     for I:=1 to RecordCount do begin
       RecNo:=I;
       if FieldByName('id_conta').AsString = DBLookupListBox1.KeyValue then begin
          SaldoAtualEdit.Caption:=FieldByName('saldo').AsString;
       end;
       Soma:= Soma+FieldByName('saldo').AsFloat;
     end;
       TotalEdit.Caption:=FloatToStr(Soma);
   end;
end;

procedure TLancamentosFrame.SpeedButton1Click(Sender: TObject);
begin
  if DBLookupListBox1.GetSelectedText = '' then begin
    ShowMessage('Selecione uma conta');
  end else begin
    GerencialData.BuscaLancamentos(dataInicial.Text, dataFinal.Text, DBLookupListBox1.KeyValue);
  end;
end;

initialization
  {$I lancamentosfr.lrs}

end.

